#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>

#define SYSCALL_GET_222 222
#define SYSCALL_PUT_223 223
#define SYSCALL_DEL_251 251

struct test_data {
   char *value;
   size_t vsize;
   char *key;
   size_t ksize;
};

void sys_put(const char *key, size_t ksize, const char *value, size_t vsize){
	syscall(SYSCALL_PUT_223, key, ksize, value, vsize);	
}

int main(int argc, char *argv[]){
	char key[100];
	char value[100];
	unsigned long cnt = 0;

	struct test_data data;
	data.key = key;
	data.value = value;

	/* start timer */
#ifdef MS_TEST
	/* calculate runtime in us */
	struct timeval start, end;
	unsigned long timer;
	gettimeofday(&start,NULL);
#else
	/* caculate runtime in ns */
	struct timespec time_start={0, 0}, time_end={0, 0};
	clock_gettime(CLOCK_REALTIME, &time_start);
#endif

	while(1){
		puts("put>>");
		memset(key, 0, sizeof(key));
		memset(value, 0, sizeof(value));
	
		puts("key:");
		fgets(key, sizeof(key), stdin);
		key[strlen(key) - 1] = '\0';			//delete '\n'
		
		puts("value:");
		fgets(value, sizeof(value), stdin);
		value[strlen(value) - 1] = '\0';			//delete '\n'

		data.ksize = strlen(key) + 1;
		data.vsize = strlen(value) + 1;

		syscall(SYSCALL_PUT_223, data.key, data.ksize, 
								data.value, data.vsize);	

		fprintf(stdout, "[put] [%s(k)]--[%s(v)]\n", data.key, data.value);
	}

	return 0;
}
